package com.powernode.sqlinjection;

import com.powernode.commons.util.DbUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Author Arrebol
 * @Date 2024/8/1 23:24
 * @Project jdbc
 * @Description：
 * 使用PreparedStatement完成修改操作
 */
public class JdbcTestPreparedStatement2 {
    public static void main(String[] args) {
        Connection conn=null;
        PreparedStatement ps=null;
        try {
            conn= DbUtils.getConnection();
            String updateSql="update t_user set id = ?, username = ? ,password = ? ," +
                    "real_name = ?, tel = ? where id = 3";
            ps=conn.prepareStatement(updateSql);
            ps.setLong(1,1910000);
            ps.setString(2,"风吹故里.");
            ps.setString(3,"mkj123");
            ps.setString(4,"马康吉");
            ps.setString(5,"1311111111");
            int count = ps.executeUpdate();
            System.out.println("执行的SQL语句为："+updateSql);
            System.out.println("更改了"+count+"条记录");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DbUtils.close(null,ps,conn);
        }
    }
}
